package the.workshop.bu.controller;

import org.springframework.web.bind.annotation.*;
import org.wisteria.framework.web.APIResult;
import the.broccoli.auth.UserContext;
import the.workshop.bu.dto.req.CustomerTelModifyReq;
import the.workshop.bu.entity.CustomerTel;
import the.workshop.bu.service.ICustomerTelService;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/bu/customer/tel")
public class CustomerTelController {

    @Resource
    private ICustomerTelService customerTelService;

    @PostMapping("/modify")
    public APIResult modify(CustomerTelModifyReq req) {
        CustomerTel customerTel = req.toCustomerTel();
        customerTel.setModifiedId(UserContext.userId());
        customerTel.setModifiedName(UserContext.userName());
        customerTelService.updateById(customerTel);
        return APIResult.success();
    }

    @PostMapping("/remove")
    public APIResult remove(@RequestParam(value = "ids") List<Integer> ids) {
        customerTelService.removeByIds(ids, UserContext.userId(), UserContext.userName());
        return APIResult.success();
    }

    @PostMapping("/isLegal")
    public APIResult isLegal(@RequestParam(value = "id") Integer id) {
        customerTelService.setLegalTel(id, UserContext.userId(), UserContext.userName());
        return APIResult.success();
    }
}
